package templateDesigner

import util.*

/**
 *
 * @author Leandro Carrasco
 * 
 */
class AuthorizationController {

    //--------------------------------------------------------------------------
    
    def authorizationService
    
    def login = {
        
        if (params.doit){
            def login = authorizationService.getLogin(params.nombre, params.password)
            if (login)
            {
                // Setea el usuario en la session
                session.templateDesignContext = new TDSession( userId: login.id, userName: login.nombre )
                
                //redirect(controller:'records', action:'list')
                redirect(controller:'home', action:'index')
                return
            }
            else
            {
                // FIXME: i18n
                flash.message = "Login incorrrecto"
            }
        }
        return []
    }
    
    //--------------------------------------------------------------------------
    
    def logout = {
        session.templateDesignContext = null
        redirect(action:'login')
    }
    
    //--------------------------------------------------------------------------
}

